package ticket;
import java.lang.*;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

import thread.RunnableTest;

public class TicketRunnable implements Runnable {
    int ticket = 100;
    @Override
    public void run() {
        while(ticket>0) {
            try {
                Thread.sleep(500);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            String name = Thread.currentThread().getName();
            Lock lock=new ReentrantLock();
            lock.lock();
            System.out.println(name + "正常出售" + (ticket--) + "张票");
            lock.unlock();
        }
    }
}
